package com.lyl.momanapp.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ListView;

import com.google.gson.Gson;
import com.lyl.momanapp.R;
import com.lyl.momanapp.adapter.StoresAdapter;
import com.lyl.momanapp.bean.StorseBean;
import com.lyl.momanapp.bean.URL;
import com.lyl.momanapp.util.utlis.MyUtils;
import com.lyl.momanapp.util.view.MyBaseActivity;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 名字 梁亚龙
 * 时间 2017/12/4.
 * QQ邮箱 503934353@qq.com
 */

public class StoresActivity extends MyBaseActivity {

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case URL.ID_stores: {
                    String s = "{\"data\":" + msg.obj.toString() + "}";
                    StorseBean storseBean = new Gson().fromJson(s, StorseBean.class);
                    StoresAdapter storesAdapter = new StoresAdapter(StoresActivity.this, (ArrayList<StorseBean.DataBean>) storseBean.getData());
                    mLV.setAdapter(storesAdapter);
                    storesAdapter.setOnItemClickLitener(new StoresAdapter.OnItemClickLitener() {
                        @Override
                        public void onItemClick() {
                            StoresActivity.this.finish();
                        }
                    });


                }
                break;
            }
        }
    };
    private ListView mLV;

    @Override
    public void initUI() {
        setContentView(R.layout.activity_stores);
        mLV = ((ListView) findViewById(R.id.stores_lv));

    }

    @Override
    public void initData() {
        HashMap<String, String> map = new HashMap<>();
        new MyUtils().xUtilsGet(URL.URL_stores, map, handler, URL.ID_stores);
    }

    @Override
    public void addListeners() {
            findViewById(R.id.fanhui).setOnClickListener(this);
        findViewById(R.id.zhuye).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
            switch (v.getId()){
                case R.id.fanhui:{
                    StoresActivity.this.finish();
                }
                break;
                case R.id.zhuye:{
                    startActivity(new Intent(StoresActivity.this,MainActivity.class));
                }
                break;
            }
    }
}
